From 3d95d58003486f471d73cfbefba347aa4a484436 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Fri, 31 Mar 2006 10:07:55 +0100 Subject: [PATCH] Enable the setting and trapping of breakpoints for hvm guest. Catch Ctrl-C for gdbserver and let gdb break from continue command. Signed-Off-By: Nitin A Kamble --- .../gdb/gdbserver/server.c | 33 +++++++++++++++++++ tools/libxc/xc_ptrace.c | 10 ++++-- xen/arch/x86/hvm/vmx/vmx.c | 8 +++++ xen/include/asm-x86/hvm/support.h | 1 + 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/server.c b/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/server.c index c987c0eb9d..3e1f50ea49 100644 --- a/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/server.c +++ b/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/server.c @@ -286,6 +286,21 @@ handle_v_requests (char *own_buf, char *status, unsigned char *signal) return; } +void +handle_breakpoint_requests (char *own_buf, char *status, unsigned char *signal) +{ + /* Currently we only support software breakpoints */ + switch (own_buf[1]) { + case '0': /* software breakpoint, int3 based */ + own_buf[0] = '\0'; + break; + case '1': /* hardware breakpoint */ + default: + write_enn (own_buf); + break; + } +} + void myresume (int step, int sig) { @@ -322,6 +337,18 @@ gdbserver_usage (void) "HOST:PORT to listen for a TCP connection.\n"); } +extern control_c_pressed_flag; +#include + +void ctrl_c_handler(int signo) +{ + printf("Ctrl-C pressed: Quit from the attached gdb first\n"); + control_c_pressed_flag = 1; +} + +struct sigaction ctrl_c_sigaction = { .sa_handler = ctrl_c_handler }; +struct sigaction old_sigaction; + int main (int argc, char *argv[]) { @@ -396,9 +423,11 @@ main (int argc, char *argv[]) } } + while (1) { remote_open (argv[1]); + sigaction(SIGINT, &ctrl_c_sigaction, &old_sigaction); restart: setjmp (toplevel); @@ -587,6 +616,9 @@ main (int argc, char *argv[]) /* Extended (long) request. */ handle_v_requests (own_buf, &status, &signal); break; + case 'Z': + handle_breakpoint_requests (own_buf, &status, &signal); + break; default: /* It is a request we don't understand. Respond with an empty packet so that gdb knows that we don't support this @@ -643,5 +675,6 @@ main (int argc, char *argv[]) "GDBserver will reopen the connection.\n"); remote_close (); } + sigaction(SIGINT, &old_sigaction, NULL); } } diff --git a/tools/libxc/xc_ptrace.c b/tools/libxc/xc_ptrace.c index f83005b45c..30fe1db22e 100644 --- a/tools/libxc/xc_ptrace.c +++ b/tools/libxc/xc_ptrace.c @@ -401,6 +401,8 @@ map_domain_va( return map_domain_va_32(xc_handle, cpu, guest_va, perm); } +int control_c_pressed_flag = 0; + static int __xc_waitdomain( int xc_handle, @@ -419,7 +421,6 @@ __xc_waitdomain( op.cmd = DOM0_GETDOMAININFO; op.u.getdomaininfo.domain = domain; - retry: retval = do_dom0_op(xc_handle, &op); if ( retval || (op.u.getdomaininfo.domain != domain) ) @@ -432,12 +433,17 @@ __xc_waitdomain( if ( options & WNOHANG ) goto done; + if (control_c_pressed_flag) { + xc_domain_pause(xc_handle, domain); + control_c_pressed_flag = 0; + goto done; + } + if ( !(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED) ) { nanosleep(&ts,NULL); goto retry; } - /* XXX check for ^C here */ done: if (get_online_cpumap(xc_handle, &op.u.getdomaininfo, &cpumap)) printf("get_online_cpumap failed\n"); diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 623fb22922..5f7fa0221e 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -2130,6 +2130,14 @@ asmlinkage void vmx_vmexit_handler(struct cpu_user_regs regs) break; } + case TRAP_int3: + { + if ( test_bit(_DOMF_debugging, &v->domain->domain_flags) ) + domain_pause_for_debugger(); + else + vmx_inject_exception(v, TRAP_int3, VMX_DELIVER_NO_ERROR_CODE); + break; + } #endif case TRAP_no_device: { diff --git a/xen/include/asm-x86/hvm/support.h b/xen/include/asm-x86/hvm/support.h index 043754546a..22b24e392c 100644 --- a/xen/include/asm-x86/hvm/support.h +++ b/xen/include/asm-x86/hvm/support.h @@ -94,6 +94,7 @@ enum hval_bitmaps { #else #define MONITOR_DEFAULT_EXCEPTION_BITMAP \ ( EXCEPTION_BITMAP_PG | \ + EXCEPTION_BITMAP_BP | \ EXCEPTION_BITMAP_GP ) #endif -- 2.30.2